﻿using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

#nullable disable

namespace WZN_shop.Models.Database
{
    public partial class WZN_ShopContext : DbContext
    {
        public WZN_ShopContext()
        {
        }

        public WZN_ShopContext(DbContextOptions<WZN_ShopContext> options)
            : base(options)
        {
        }

        public virtual DbSet<Classification> Classifications { get; set; }
        public virtual DbSet<Good> Goods { get; set; }
        public virtual DbSet<OrderDetil> OrderDetils { get; set; }
        public virtual DbSet<Porder> Porders { get; set; }
        public virtual DbSet<ShopCar> ShopCars { get; set; }
        public virtual DbSet<User> Users { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
                optionsBuilder.UseSqlServer("Data Source=223.247.140.116,57587;Initial Catalog=WZN_Shop;User ID=sa;Password=Yixuhongxi1");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.HasAnnotation("Relational:Collation", "Chinese_PRC_CI_AS");

            modelBuilder.Entity<Classification>(entity =>
            {
                entity.HasNoKey();

                entity.ToTable("Classification");

                entity.Property(e => e.Classifi)
                    .IsRequired()
                    .HasMaxLength(50)
                    .HasColumnName("classifi");

                entity.Property(e => e.GoodClass)
                    .IsRequired()
                    .HasMaxLength(50);
            });

            modelBuilder.Entity<Good>(entity =>
            {
                entity.Property(e => e.GoodBrief)
                    .IsRequired()
                    .HasMaxLength(255);

                entity.Property(e => e.GoodClass)
                    .IsRequired()
                    .HasMaxLength(50);

                entity.Property(e => e.GoodImg)
                    .IsRequired()
                    .HasMaxLength(255);

                entity.Property(e => e.GoodName)
                    .IsRequired()
                    .HasMaxLength(64);

                entity.Property(e => e.GoodPrice).HasColumnType("decimal(18, 2)");

                entity.Property(e => e.GoodStatic)
                    .IsRequired()
                    .HasMaxLength(50);
            });

            modelBuilder.Entity<OrderDetil>(entity =>
            {
                entity.HasKey(e => new { e.OrderId, e.GoodId });

                entity.ToTable("OrderDetil");

                entity.HasIndex(e => e.OrderId, "IX_OrderDetil");

                entity.Property(e => e.Price).HasColumnType("decimal(18, 2)");

                entity.Property(e => e.UnitPrice)
                    .HasColumnType("decimal(18, 2)")
                    .HasColumnName("unitPrice");
            });

            modelBuilder.Entity<Porder>(entity =>
            {
                entity.HasKey(e => e.OrderId);

                entity.ToTable("POrder");

                entity.Property(e => e.Ostatic)
                    .IsRequired()
                    .HasMaxLength(50)
                    .HasColumnName("OStatic");

                entity.Property(e => e.Price).HasColumnType("decimal(18, 2)");
            });

            modelBuilder.Entity<ShopCar>(entity =>
            {
                entity.ToTable("Shop_car");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Count).HasColumnName("count");

                entity.HasOne(d => d.User)
                    .WithMany(p => p.ShopCars)
                    .HasForeignKey(d => d.UserId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("FK_Shop_car_Users");
            });

            modelBuilder.Entity<User>(entity =>
            {
                entity.Property(e => e.Createtime)
                    .HasColumnType("datetime")
                    .HasColumnName("createtime")
                    .HasDefaultValueSql("(getdate())");

                entity.Property(e => e.Email)
                    .HasMaxLength(50)
                    .HasColumnName("email");

                entity.Property(e => e.Hand)
                    .HasMaxLength(64)
                    .HasColumnName("hand");

                entity.Property(e => e.Name)
                    .HasMaxLength(50)
                    .HasColumnName("name");

                entity.Property(e => e.Password)
                    .IsRequired()
                    .HasMaxLength(64)
                    .HasColumnName("password");

                entity.Property(e => e.Phone)
                    .IsRequired()
                    .HasMaxLength(50)
                    .HasColumnName("phone");
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
